%%  
% f(x)=(Ax-b)^2
clear all;clc;
init=ones(10,1);
num=10000;dim=length(init);
rand('seed',10);
A=randn(num,dim);
sol=rand(dim,1);
b=A*sol;

prox=@(x,c)(prox_lst(x,A,b,c));
theta=0;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-')
grid on;
hold on;


theta=0.3;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'--')



theta=0.6;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')

theta=0.9;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')


legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9');
%%  
% f(x)=|Ax-b|
clear all;clc;
init=zeros(100,1);
randn('seed',10);
num=10000;dim=length(init);

A=randn(num,dim);
sol=rand(dim,1);
b=A*sol;

prox=@(x,c)(prox_abs(x,A,b,c));

theta=0;
[x,path]= prox_nag(prox,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-')
grid on;
hold on;

theta=0.3;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'--')

theta=0.6;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')

theta=0.9;

[x,path]=prox_nag(prox,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')

legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9');